package javango.forms.fields;

import java.util.Map;

import com.google.inject.Inject;

import javango.forms.widgets.WidgetFactory;

public class MultipleLongChoiceField extends LongChoiceField {

	@Inject
	public MultipleLongChoiceField(WidgetFactory widgetFactory) {
		super(widgetFactory);
	}

	@Override
	public Object clean(String[] values, Map<String, String> errors) {
		Long[] clean = new Long[values.length];
		int i=0;
		for(String val : values) {
			Long longValue = (Long)clean(val, errors);
			if (!getChoices().containsKey(longValue)) {
				errors.put(this.name, "Select a valid choice.  That choice is not one of the available choices.");
			}
			clean[i++] = longValue; 
		}
		return clean;
	}

	
}
